package com.ruoyi.controller.production;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.production.MesWorkOrderProcess;
import com.ruoyi.service.production.IMesWorkOrderProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 工单工序记录Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/production/workorderprocess")
public class MesWorkOrderProcessController extends BaseController
{
    @Autowired
    private IMesWorkOrderProcessService IMesWorkOrderProcessService;

    /**
     * 查询工单工序记录列表
     */
    @PreAuthorize("@ss.hasPermi('production:workorderprocess:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesWorkOrderProcess mesWorkOrderProcess)
    {
        startPage();
        List<MesWorkOrderProcess> list = IMesWorkOrderProcessService.selectMesWorkOrderProcessList(mesWorkOrderProcess);
        return getDataTable(list);
    }

    /**
     * 导出工单工序记录列表
     */
    @PreAuthorize("@ss.hasPermi('production:workorderprocess:export')")
    @Log(title = "工单工序记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesWorkOrderProcess mesWorkOrderProcess)
    {
        List<MesWorkOrderProcess> list = IMesWorkOrderProcessService.selectMesWorkOrderProcessList(mesWorkOrderProcess);
        ExcelUtil<MesWorkOrderProcess> util = new ExcelUtil<MesWorkOrderProcess>(MesWorkOrderProcess.class);
        util.exportExcel(response, list, "工单工序记录数据");
    }

    /**
     * 获取工单工序记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:workorderprocess:query')")
    @GetMapping(value = "/{processId}")
    public AjaxResult getInfo(@PathVariable("processId") Long processId)
    {
        return success(IMesWorkOrderProcessService.selectMesWorkOrderProcessByProcessId(processId));
    }

    /**
     * 新增工单工序记录
     */
    @PreAuthorize("@ss.hasPermi('production:workorderprocess:add')")
    @Log(title = "工单工序记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesWorkOrderProcess mesWorkOrderProcess)
    {
        return toAjax(IMesWorkOrderProcessService.insertMesWorkOrderProcess(mesWorkOrderProcess));
    }

    /**
     * 修改工单工序记录
     */
    @PreAuthorize("@ss.hasPermi('production:workorderprocess:edit')")
    @Log(title = "工单工序记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesWorkOrderProcess mesWorkOrderProcess)
    {
        return toAjax(IMesWorkOrderProcessService.updateMesWorkOrderProcess(mesWorkOrderProcess));
    }

    /**
     * 删除工单工序记录
     */
    @PreAuthorize("@ss.hasPermi('production:workorderprocess:remove')")
    @Log(title = "工单工序记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{processIds}")
    public AjaxResult remove(@PathVariable Long[] processIds)
    {
        return toAjax(IMesWorkOrderProcessService.deleteMesWorkOrderProcessByProcessIds(processIds));
    }

    /**
     * 根据工单ID查询工序记录列表
     */
    @PreAuthorize("@ss.hasPermi('production:workorderprocess:list')")
    @GetMapping("/listByOrderId/{orderId}")
    public AjaxResult listByOrderId(@PathVariable Long orderId)
    {
        List<MesWorkOrderProcess> list = IMesWorkOrderProcessService.selectProcessByOrderId(orderId);
        return success(list);
    }

    /**
     * 根据工单编号查询工序记录列表
     */
    @PreAuthorize("@ss.hasPermi('production:workorderprocess:list')")
    @GetMapping("/listByOrderCode/{orderCode}")
    public AjaxResult listByOrderCode(@PathVariable String orderCode)
    {
        List<MesWorkOrderProcess> list = IMesWorkOrderProcessService.selectProcessByOrderCode(orderCode);
        return success(list);
    }

    /**
     * 根据设备ID查询工序记录列表
     */
    @PreAuthorize("@ss.hasPermi('production:workorderprocess:list')")
    @GetMapping("/listByEquipmentId/{equipmentId}")
    public AjaxResult listByEquipmentId(@PathVariable Long equipmentId)
    {
        List<MesWorkOrderProcess> list = IMesWorkOrderProcessService.selectProcessByEquipmentId(equipmentId);
        return success(list);
    }

    /**
     * 根据操作工ID查询工序记录列表
     */
    @PreAuthorize("@ss.hasPermi('production:workorderprocess:list')")
    @GetMapping("/listByWorkerId/{workerId}")
    public AjaxResult listByWorkerId(@PathVariable Long workerId)
    {
        List<MesWorkOrderProcess> list = IMesWorkOrderProcessService.selectProcessByWorkerId(workerId);
        return success(list);
    }

    /**
     * 根据状态查询工序记录列表
     */
    @PreAuthorize("@ss.hasPermi('production:workorderprocess:list')")
    @GetMapping("/listByStatus/{status}")
    public AjaxResult listByStatus(@PathVariable String status)
    {
        List<MesWorkOrderProcess> list = IMesWorkOrderProcessService.selectProcessByStatus(status);
        return success(list);
    }
}